package com.itheima.homework.homework3;
/*
某电影院目前正在上映国产大片，共有100张票，而它有3个窗口卖票，
请设计一个程序模拟该电影院卖票，并保证线程同步，不会出现错误的买票数据。
 */
public class Dmeo3 {
    public static void main(String[] args) {
        MyTicket mt = new MyTicket();
        Thread t2 = new Thread(mt);
        Thread t1 = new Thread(mt);
        Thread t3 = new Thread(mt);
        t2.setName("窗口二");
        t1.setName("窗口一");
        t3.setName("窗口三");
        t1.start();
        t2.start();
        t3.start();
    }
}
class MyTicket extends Thread{
    private int ticket = 100;
    @Override
    public void run() {
        while(true){
            synchronized ("ab"){
                if(ticket <= 0){
                    break;
                }else{
                    ticket--;
                    System.out.println(Thread.currentThread().getName()+"还剩"+ticket+"张票");
                }
            }
        }

    }
}